package com.woniuxy.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.*;
import com.woniuxy.service.SortService;
import com.woniuxy.service.StaffService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Staff)表控制层
 *
 * @author makejava
 * @since 2021-05-15 14:52:40
 */
@RestController
@RequestMapping("staff")
public class StaffController {
    /**
     * 服务对象
     */
    @Resource
    private StaffService staffService;
    @Resource
    private SortService sortService;

//    //数据库取出的数据对象
//    @Autowired(required=true)
//    Staff oldstaff;
//这样比较复杂还是直接改xml比较简单,因为set获取get以及resultmap类型,没有改xml的字段快
//    //前端需求的数据对象
//    @Autowired(required=true)
//    Staff newstaff;




    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping("selectOne")
    public Staff SelectOne(Integer id) {
        return this.staffService.queryById(id);
    }
    /**
     * 条件查询所有数据
     * @return 集合
     */
//    @RequestMapping("selectAll")
//    public List<Staff> SelectAll(Staff staff) {
//        return this.staffService.queryAll(staff);
//    }


    @GetMapping("selectAll")
    public PageInfo<Staff> SelectAll(int startpage, int pagesize){
        PageHelper.startPage(startpage,pagesize);
        Staff staff=null;
        Page<Staff> page = (Page<Staff>) this.staffService.queryAll(staff);
        PageInfo<Staff> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }






    @PostMapping("search")
    public PageInfo<Staff> search(@RequestBody StaffDto staffDto){
        PageHelper.startPage(staffDto.getPage(),staffDto.getLimit());
        Page<Staff> page =(Page<Staff>) this.staffService.queryAll(staffDto.getStaff());
        PageInfo<Staff>pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    /**
     * 添加一条数据
     *
     * @param staff
     * @return 单条数据
     */
    @PostMapping("insertOne")
    public Staff InsertOne(@RequestBody Staff staff) {
        return this.staffService.insert(staff);
    }


    /**
     * 添加一条数据
     *
     * @param staff
     * @return 单条数据
     */
    @PostMapping("updateOne")
    public Staff UpdateOne(@RequestBody Staff staff) {
        return this.staffService.update(staff);
    }

    /**
     * 添加一条数据
     *
     * @param staffId
     * @return 单条数据
     */
    @PostMapping("deleteOne/{staffId}")
    public boolean DelectOne(@PathVariable("staffId") Integer staffId) {
        return this.staffService.deleteById(staffId);
    }


    /**
     * Auther: Hello Mr. Guo  <br/>
     * Date: 19:08:2021/5/24  <br/>
     * Description:技师轮巡对象
     */
    @GetMapping("selectStaff")
    @ApiOperation("当前轮巡技师")
    public ResponseEntity<Sort> selectStaff(){
        if (this.sortService.sortroundexit()){
            Sort sortbegin = this.sortService.sortbegin();
            if (sortbegin!=null){
                return new ResponseEntity(1,"查询当前轮巡技师成功",sortbegin);
            }
            return new ResponseEntity(0,"查询当前轮巡技师失败");
        }else {
            return  new ResponseEntity(1,"暂无空闲技师");
        }
    }



//        Sort sortbegin = this.sortService.sortbegin();
//        if (sortbegin!=null){
//            return new ResponseEntity(1,"查询当前轮巡技师成功",sortbegin);
//        }
//        return new ResponseEntity(0,"查询当前轮巡技师失败");
//    }

    /**
     * Auther: Hello Mr. Guo  <br/>
     * Date: 17:04:2021/5/25  <br/>
     * Description:所有技师列表
     */
//    @GetMapping("selectAllStaff")
//    @ApiOperation("所有技师列表")
//    private ResponseEntity<Staff> selectAllStaff(){
//        List<Staff> staff = this.staffService.selcetAllStaff();
//        if (staff != null) {
//            return new ResponseEntity(1,"查询技师列表成功" , staff);
//        }
//        return new ResponseEntity(0,"查询技师列表失败");
//    }


    //请求所有技师不分页
    @PostMapping("selectAllStaff")
    @ApiOperation("请求所有技师不分页")
    public ResponseEntity<Staff> selectAllStaff(@RequestBody Staff staff){
        List<Staff> list= this.staffService.queryAll(staff);
        if (list != null){
            return new ResponseEntity(1,"查询所有技师成功",list);
        }
        return new ResponseEntity(0,"查询所有技师失败");
    }

    /*前端业务接口*/
    /**技师请假接口
    *http://staff/updatestatus
    * */
    @GetMapping("updatestatus")
    @ApiOperation("技师请假接口")
    public ResponseEntity updatestatus( Integer staffId){
        int i = staffService.updatestatus(staffId);
        if (i > 0 ){
            return new ResponseEntity(1,"技师请假成功");
        }
        return new ResponseEntity(0,"技师请假失败");
    }

    /**技师请假完成接口
     *http://staff/updatestatusend
     * */
    @GetMapping("updatestatusend")
    @ApiOperation("请假结束接口")
    public ResponseEntity updatestatusend( Integer staffId){
        int updatestatusend = this.staffService.updatestatusend(staffId);
        if (updatestatusend > 0){
            return new ResponseEntity(1,"请假完成接口更新成功");
        }
        return new ResponseEntity(0,"请假结束接口更新失败");
    }

    /**前端业务
     * get
     * 查询空闲技师,房间,床位,项目的情况
     *http://staff/selectstaffroom
     * */
    @GetMapping("selectstaffroom")
    @ApiOperation("查询空闲技师,房间,床位,项目的情况接口")
    public ResponseEntity selectstaffroom(){
        List<Staffroom> list = this.staffService.selectstaffroom();
        if (list != null){
            return new ResponseEntity(1,"查询所有技师成功",list);
        }
        return new ResponseEntity(0,"查询所有技师失败");
    }

}
